#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "sdlUtilities.h"
#include "town.h"
//#include <SDL_thread.h>
//#include <SDL.h>

/* GP2X button mapping */


/* The screen surface, joystick device */

#ifdef WIN32
	/* Only use Windows code here */


#endif

#undef main

SDL_Surface *screen;
SDL_Surface *Outscreen;
SDL_Joystick *joy;
extern SDL_Event  event;

void Terminate(void)
{
	SDL_Quit();
#ifdef GP2X
	chdir("/usr/gp2x");
	execl("/usr/gp2x/gp2xmenu", "/usr/gp2x/gp2xmenu", NULL);
#endif
}




int main (int argc, char *argv[])
{

    
    int done;

    
	
	

	/* Initialize SDL */

	//initSdlGP();
	if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0) {
		fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ());
		exit (1);
	}




	atexit (Terminate);
  
	

	/* Set 320x240 16-bits video mode */

	screen = SDL_SetVideoMode (320, 240, 8, SDL_HWSURFACE);

	if (screen == NULL) {
		fprintf (stderr, "Couldn't set 320x240x16 video mode: %s\n", SDL_GetError ());
		exit (2);
	}


	/* Check and open joystick device */
	if (SDL_NumJoysticks() > 0) {
		joy = SDL_JoystickOpen(0);
		if(!joy) {
			fprintf (stderr, "Couldn't open joystick 0: %s\n", SDL_GetError ());
		}
	}
	TTF_Init();
SDL_ShowCursor(SDL_DISABLE);

#ifdef GP2X
	/* Only use GP2X code here */
#endif

#ifdef WIN32
	/* Only use Windows code here */
#endif
      /*SDL_Thread *k;
      k=SDL_CreateThread(Fps, NULL);*/
      
	done = 0;
	rectSdl(0,0,320,240, WHITE);
	
	
	
	
	
	
    updateRectSdl(0, 0, 320, 240);
	/*town LDE;
	
    LDE.load("./data/town/LDE.desc");
	LDE.done=&done;*/
	headquarter head;
    
    
    while (!done)
	{
		//SDL_Event event;
        head.run();
        
		/* Check for events */

		/* Processing */
	}
    
	return 0;
}



